package learn.spring.api.controller;


import learn.spring.api.entity.User;
import learn.spring.api.service.IUserService;
import learn.spring.common.base.Result;
import learn.spring.common.dto.UserDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author chins
 * @since 2021-12-18
 */
@RestController
@RequestMapping("/api/user")
public class UserController {

  @Autowired
  private IUserService userService;

  @GetMapping("/{username}")
  public Result getUserByName(@PathVariable String username) {
    User userByName = userService.getUserByName(username);

    return Result.success().data("user",
        UserDto.builder().userId(userByName.getUserId()).username(userByName.getUsername())
            .password(userByName.getPassword())
            .build());
  }
}
